//只能输入数字
function numMust(obj)

{
  //先把非数字的都替换掉，除了数字和.
  obj.value = obj.value.replace(/[^\d.]/g,"");
}

//只能输入正整数
function number(obj)

{
  //先把非数字的都替换掉，除了数字和.
  obj.value = obj.value.replace(/[^\d+$]/g,"");
}
//只能输入数字和小数点
function numOne(obj)

{
	 //先把非数字的都替换掉，除了数字和.
	  obj.value = obj.value.replace(/[^\d.]/g,"");
	  //必须保证第一个为数字而不是.
	  obj.value = obj.value.replace(/^\./g,"");
	  //保证只有出现一个.而没有多个.
	  obj.value = obj.value.replace(/\.{2,}/g,".");
	  //保证.只出现一次，而不能出现两次以上
	  obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");

	  obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d).*$/, '$1$2.$3'); //只能输入两个小数

}

// 只能输入0-5之间的小数,限制一位小数点
function numFive(obj) {
	if (!(/^[0-9]+(.[0-9]{0,2})?$/.test(obj.value))) {
		obj.value = "";
	}
	if (obj.value > 5) {
		obj.value = "5";
	}
	if (obj.value < 0) {
		obj.value = "0";
	}
}
function addOrUp(form1,url){
	$.ajax({
	url : url,
	data : $(form1).serialize(),
	method : 'post',
	dataType : 'json',
	success : function(data) {
		if (data == 1) {
			layer.msg('操作成功.', {
				icon : 6
			});
			refresh();
		} else {
			layer.msg('操作失败.', {
				icon : 5
			});
		}
	}
})
}
function addForm(title, windowId,form1) {
	$(form1)[0].reset();
	openLayer(title, windowId);
}
// 弹窗
function openLayer(title, content, ctSize) {

	var size;

	if (ctSize == undefined || ctSize == "" || ctSize == null) {
		size = [ '70%', '85%' ];
	} else {
		size = ctSize;
	}

	layer.open({
		type : 1,
		title : title,
		shade : [ 0 ],
		area : size,
		maxmin : true,
		content : $(content)
	})
}

// 刷新
function refresh() {
	load($(".ibox-content"));
	window.location.reload();
}

/* 重置 */

function reset() {
	load($(".ibox-content"));
  $("#searchForm").reset();
  $("#searchForm").submit();

}
function reset(tableId) {
	
	tableId[0].reset();
};

// 提示弹窗
function showMsg(msg, icon, title) {

	var titles;

	if (title == undefined || title == "" || title == null) {
		titles = "系统提示";
	} else {
		titles = title;
	}

	layer.alert(msg, {
		skin : 'layui-layer-molv',
		icon : icon,
		title : titles
	});
}

/* 全选/取消全选 */
var selAll = function(tableId, obj) {
	tableId.find('input:checkbox').each(function() {
		$(this).prop('checked', obj.checked);
	});
};

/* 删除多条记录 */
var delBySel = function(obj,url) {
	
  //获取多选框的value值
  var ids = "";
  obj.find('input[data-ck="ids"]:checked').each(function () {
    ids += ids == "" ? $(this).val() : "," + $(this).val();
  });

  if(ids.length < 1 || ids == "" || ids == null || ids == undefined) {
    layer.msg('你还没有选择任何内容！', {icon: 5});
    return;
  }

  layer.msg('你确定删除当前选中的数据吗？', {
    time: 0 //不自动关闭

    ,btn: ['确定', '取消']

    ,yes: function(){
      // 删除数据成功
    	
      layer.msg('删除数据成功.', {icon: 6});
      load($(".ibox-content"));
      location.href=url+"?ids="+ids;
      // 删除数据失败
      //layer.msg('删除数据失败.', {icon: 5});

      
    }
  });
};


/* 删除一条记录 */
var delById = function (url) {

  layer.msg('你确定删除当前的数据吗？', {
    time: 0 //不自动关闭
    ,btn: ['确定', '取消']
    ,yes: function(){
    	 // 删除数据成功
        layer.msg('删除数据成功.', {icon: 6});
        load($(".ibox-content"));
    	location.href = url;
      //删除数据失败
      //layer.msg('删除数据失败.', {icon: 5});

    }
  });

};





function searchSubmit(){
	load($(".ibox-content"));
  $('#searchForm').submit();
}


//选择品牌——添加class='selectBrand'



/************
 ** Layui模块化
 ** 全局弹窗和表单模块
 *************/


var layer;
var form;
var laydate;


layui.use(['laydate','layer','form'], function() {
  layer = layui.layer; //弹层
  form = layui.form; //form表单
  laydate = layui.laydate;//日期
  //form表单
  
  //设置所有日期
  setLaydate('#setuptime');
  setLaydate('#birthdayAdd');
  setLaydate('#intoDateAdd');
  setLaydate('#beginCreateDate');
  setLaydate('#endCreateDate');
  setLaydate('#orderTimeUpe');
  setLaydate('#orderOkTimeUpe');
  setLaydate('#orderEndtimeUpe');
  setLaydate('#beginOrderTime');
  setLaydate('#endOrderTime');

  setLaydate('#orderTimeAdd');
  setLaydate('#orderPayTimeAdd');
  setLaydate('#orderSentTimeUpe');
  setLaydate('#orderReceiptTimeAdd');
  setLaydate('#orderEvalTimeAdd');
  setLaydate('#date');
  setLaydate('#date1');
  setLaydate('#date2');
  
});


  //添加日期功能
  function setLaydate(select){
    if($(select).length != 0){
      laydate.render({elem: select});
    }
  }
  var ossUrl = "http://formal.yzb.store/";
  
  function getDictLabel(type,value){
	  var label= "";
	  $.ajax({
	    	url : '/NewYzb/user/getDictLabel',
	    	method: 'post',
	    	data: {"value":value,"type": type},
	    	async:false,
	    	success:function(data){
	    		label = data;
	    	 }
	       });
	  	
	       return 	label;
  };


  function getStore(){
	  var store;
	  $.ajax({
	    	url : '/NewYzb/user/getStore',
	    	method: 'post',
	    	data: {},
	    	dataType:'json',
	    	async:false,
	    	success:function(data){
	    		store = data;
	    	 }
	       });
	       return store;
  }
  
  var store = getStore();

  function selectBrand(e,url){
		  e.preventDefault();
			layer.open({
			      type: 2,
			      title: "选择品牌",
			      shade: [0],
			      area: ['650px', '400px'],
			      maxmin: true,
			      content: url,
			      btn: ['确定', '关闭'],
			  	  yes: function(index, layero){
			  		var iframeWin = layero.find('iframe')[0].contentWindow; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
			  		var table = iframeWin.document.getElementById("brandTable");  
			  		// 获取多选框的value值
						var ids = "";
						var p = $(table).find('input[data-ck="ids"]:checked');
						$(table).find('input[data-ck="ids"]:checked').each(function() {
							ids += ids == "" ? $(this).val() : "," + $(this).val();
						});
						if (ids.length < 1 || ids == "" || ids == null || ids == undefined) {
							layer.msg('你还没有选择任何内容！', {
								icon : 5
							});
							return;
						}
						if (ids.length > 1) {
							var split = ids.split(",");
							if(split.length > 1){
								layer.msg('只能选择一个品牌', {
									icon : 5
								});
								return;
							}
						}
			  	    	$("#searchId").val(ids);
			  	    	 $("#brandNameSearch").val(p.parent().parent().parent().children('td').eq(1).children('div').text());
			  			 layer.close(index);//关闭对话框。
			  		  },
		});
  }
  
//菊花加载
  function load(ele){
	if($('.shadowDiv').length != 0){
		 $('.shadowDiv').remove();
	}

    var $ele = ele;
    if(ele == undefined){
      $ele = $(".layui-body");
    }

    var eleWidth = $ele.outerWidth(true);
    var eleHeight = $ele.outerHeight(true);

    var load = '<div class="shadowDiv" style="position: absolute;left:0;top:0;width:' + eleWidth + 'px ;height:' + eleHeight + 'px;background: rgba(0,0,0,.1);z-index: 19891099;"> <i class="layui-icon layui-anim layui-anim-rotate layui-anim-loop" style="font-size: 40px; color: #1E9FFF;margin: -20px 0; position: absolute; left: 50%; top: 50%;">&#xe63d;</i> </div>';

    $ele.append(load);
  }

  
  
  $(function(){


	  //菜单栏响应屏幕宽度

	  var $shrink = $("#shrink");
	  var $side = $(".layui-side");
	  var $body = $(".layui-body");
	  var $footer = $(".layui-layout-admin .layui-footer");
	  var $left = $(".layui-layout-left");
	  var $logo = $(".layui-logo");
	  var $progress = $(".layui-progress");

	  $shrink.click(function(e){
	    e.preventDefault();

	    if( $shrink.attr("data-side") == "show" ){
	      hideSide ()
	    }else {
	      showSide ()
	    }

	  });

	  //监听屏幕大小变化
	  $(window).resize(function () {

	    var width = $(window).width();

	    if(width < 768){
	      hideSide ();
	    }else{
	      showSide ();
	    }

	  });

	  //隐藏菜单栏
	  function hideSide (){
	    $body.css("left","0");
	    $footer.css("left","0");
	    $left.css("left","0");
	    $progress.css("left","0");

	    $logo.addClass("hide");
	    $logo.removeClass("show");
	    $side.addClass("hide");
	    $side.removeClass("show");

	    $shrink.attr("data-side", "hide");
	  }

	  //展开菜单栏
	  function showSide (){
	    $body.css("left","200px");
	    $footer.css("left","200px");
	    $left.css("left","200px");
	    $progress.css("left","200px");

	    $logo.addClass("show");
	    $logo.removeClass("hide");
	    $side.addClass("show");
	    $side.removeClass("hide");

	    $shrink.attr("data-side", "show");
	  }

	});

